package io.cloud.tec.config;

import io.cloud.tec.exception.ErrorResultException;
import io.cloud.tec.exception.RestApiRequestException;
import io.cloud.tec.project.model.Result;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ExtendedServletRequestDataBinder;

import java.time.Instant;

@RestControllerAdvice
public class ExceptionHandlerConfig {

    @ExceptionHandler(value = RestApiRequestException.class)   //表示当NameException的异常被抛出时，执行此方法
    public Result doNameException(RestApiRequestException e) {
        return Result.fail(e.getMessage(), e);
    }

    @ExceptionHandler(value = ErrorResultException.class)   //表示当NameException的异常被抛出时，执行此方法
    public Result doNameException(ErrorResultException e) {
        return Result.fail(e.getCode(), e.getMessage(), e);
    }
}
